package com.xingdata.jjxc.map.navi.activity;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.xingdata.jjxc.R;

public class Test extends Activity {
	private PopupWindow navigationPopupWindow = null;
	private View pop_view;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mainstart);

		((TextView) findViewById(R.id.main_start_route_text))
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						showPOP();
					}

				});
	}
	private void showPOP() {
		navigationPopupWindow = new PopupWindow(Test.this);
		pop_view = View.inflate(Test.this,
				R.layout.popupwindow_navigation, null);
		navigationPopupWindow.setContentView(pop_view);
		navigationPopupWindow
				.setWidth(LayoutParams.MATCH_PARENT);
		navigationPopupWindow
				.setHeight(LayoutParams.WRAP_CONTENT);
		navigationPopupWindow.setFocusable(true);
		navigationPopupWindow.setOutsideTouchable(false);
		navigationPopupWindow
				.setAnimationStyle(R.style.popup_fade_anim);
		// 20%黑
		ColorDrawable dw = new ColorDrawable(0x33000000);
		navigationPopupWindow.setBackgroundDrawable(dw);
		pop_view.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				int height = pop_view.findViewById(
						R.id.pop_layout).getTop();
				int y = (int) event.getY();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y < height) {
						navigationPopupWindow.dismiss();
					}
				}
				return true;
			}
		});
//		pop_view.findViewById(R.id.pop_begin)
//				.setOnClickListener(Test.this);
//		pop_view.findViewById(R.id.pop_simulate)
//				.setOnClickListener(Test.this);
		navigationPopupWindow.showAtLocation(this.findViewById(R.id.main_start_route_text),
				Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
		
	}
	
}
